package com.network.topo.snmp;

import java.io.IOException;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;

import org.snmp4j.Target;


import com.network.topo.DiscoverUtil;
import com.network.topo.dao.TopoDaoInterface;
import com.network.util.snmp4j.SnmpGet;
import com.network.util.snmp4j.SnmpGetResultSet;

public final class SysInfo extends AbstractXxxTable
{
	private static ArrayList<String> oidList = null;

	private SysInfo(SnmpGetResultSet resultSet)
	{
		this.resultSet = resultSet;
	}

	public static SysInfo getInstance(SnmpGet snmpGet, Target target)
	{
		SnmpGetResultSet sgrs = null;
		SysInfo instance = null;
		try
		{
			sgrs = snmpGet.query(getOidList(), target);
		}
		catch (IOException e)
		{
			e.printStackTrace();
		}
		if (sgrs != null && sgrs.next() == true)
		{
			instance = new SysInfo(sgrs);
		}
		return instance;
	}

	public static synchronized ArrayList<String> getOidList()
	{
		if (oidList == null)
		{
			oidList = new ArrayList<String>();
			oidList.add("1.3.6.1.2.1.1.1");
			oidList.add("1.3.6.1.2.1.1.2");
			oidList.add("1.3.6.1.2.1.1.3");
			oidList.add("1.3.6.1.2.1.1.4");
			oidList.add("1.3.6.1.2.1.1.5");
			oidList.add("1.3.6.1.2.1.1.6");
			oidList.add("1.3.6.1.2.1.1.7");
			oidList.add("1.3.6.1.2.1.1.8");
			// oidList.add("1.3.6.1.2.1.4.1");
		}
		return oidList;
	}

	public String getSysDescr()
	{
		return getValue("1.3.6.1.2.1.1.1");
	}

	public String getSysObjectId()
	{
		return getValue("1.3.6.1.2.1.1.2");
	}

	public String getSysUpTime()
	{
		return getValue("1.3.6.1.2.1.1.3");
	}

	public String getSysContact()
	{
		return getValue("1.3.6.1.2.1.1.4");
	}

	public String getSysName()
	{
		return getValue("1.3.6.1.2.1.1.5");
	}

	public String getSysLocation()
	{
		return getValue("1.3.6.1.2.1.1.6");
	}

	public int getSysServices()
	{
		return str2int(getValue("1.3.6.1.2.1.1.7"));
	}

	public String getSysORLastChange()
	{
		return getValue("1.3.6.1.2.1.1.8");
	}

	public int getIpForwarding()
	{
		return str2int(getValue("1.3.6.1.2.1.4.1"));
	}
}
